package org.springblade.modules.restaurant.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.restaurant.entity.RewardPenaltyRecord;
import org.springblade.modules.restaurant.service.IRewardPenaltyRecordService;
import org.springblade.modules.restaurant.vo.RewardPenaltyRecordVO;
import org.springframework.web.bind.annotation.*;

/**
 * @author harry
 * @公众号 Harry技术
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/restaurant/rewardpenalty")
@Tag(name = "API - 奖罚记录", description = "奖罚记录接口")
public class ApiRewardPenaltyRecordController {

	private IRewardPenaltyRecordService rewardPenaltyRecordService;

	/**
	 * 分页 奖罚记录
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "分页", description = "传入rewardPenaltyRecord")
	public R<IPage<RewardPenaltyRecord>> list(RewardPenaltyRecordVO rewardPenaltyRecord, Query query) {
		LambdaQueryWrapper<RewardPenaltyRecord> wrapper = Wrappers.lambdaQuery();
		wrapper.like(StrUtil.isNotBlank(rewardPenaltyRecord.getRewardsPenaltiesDetail()),RewardPenaltyRecord::getRewardsPenaltiesDetail, rewardPenaltyRecord.getRewardsPenaltiesDetail());
		wrapper.orderByDesc(RewardPenaltyRecord::getCreateTime);

		IPage<RewardPenaltyRecord> pages = rewardPenaltyRecordService.page(Condition.getPage(query), wrapper);
		return R.data(pages);
	}

	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "详情", description = "传入rewardPenaltyRecord")
	public R<RewardPenaltyRecord> detail(RewardPenaltyRecord rewardPenaltyRecord) {
		RewardPenaltyRecord detail = rewardPenaltyRecordService.getOne(Condition.getQueryWrapper(rewardPenaltyRecord));
		return R.data(detail);
	}

	/**
	 * 新增或修改 奖罚记录
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "新增或修改", description = "传入rewardPenaltyRecord")
	public R submit(@Valid @RequestBody RewardPenaltyRecord rewardPenaltyRecord) {
		return R.status(rewardPenaltyRecordService.saveOrUpdate(rewardPenaltyRecord));
	}

}
